package com.briup.web.controller;

import com.briup.bean.ShippingAddress;
import com.briup.bean.ShopCar;
import com.briup.bean.User;
import com.briup.service.IShippingAddressService;
import com.briup.service.IShopCarService;
import com.briup.utils.SumPrice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.List;

@Controller
public class ConfirmController {
    @Autowired
     private  IShopCarService shopCarService;
    @Autowired
    private SumPrice sumPrice;
    @Autowired
    private IShippingAddressService shippingAddressService;
    @GetMapping(value = {"/advanceOrder"})
    public String toShopCar(Long[] ids,HttpSession session , Model model){
        User user = (User) session.getAttribute("user");
        List<ShopCar> shopCarList = shopCarService.findShopCars(ids);
        model.addAttribute("shopCarList",shopCarList);

        model.addAttribute("sumPrice",sumPrice.getSumPrice(shopCarList));

        //获取地址
        List<ShippingAddress> shippingAddresses = shippingAddressService.findUserAllShippingAddress(user.getId());
        model.addAttribute("userAddressList",shippingAddresses);
        return "confirm";
    }
}
